/*
 * SpaceMenu.cpp
 *
 *  Created on: 29 mar 2010
 *      Author: Andreas
 */

#include "SpaceMenu.h"
#include "SpaceApp.h"
#include <SDL/SDL.h>
#include <vector>
#include <iostream>
#include "engine/graphics/ScreenManager.h"

using namespace std;

SpaceMenu::SpaceMenu(SpaceApp *app) : Menu("img/space/menu.png") {

	parent = app;

	// Add all buttons with SDL_Rects vector
	SDL_Rect rect;
	Button b;

	rect.x = 667;
	rect.y = 479;
	rect.w = 273;
	rect.h = 65;
	b.clip = rect;
	b.url = "img/space/button_play.png";

	buttons.push_back(rect);

	rect.x = 667;
	rect.y = 570;
	rect.w = 273;
	rect.h = 65;
	b.clip = rect;
	b.url = "img/space/button_play.png";

	buttons.push_back(rect);

	rect.x = 667;
	rect.y = 661;
	rect.w = 273;
	rect.h = 65;
	b.clip = rect;
	b.url = "img/space/button_play.png";

	buttons.push_back(rect);

}

SpaceMenu::~SpaceMenu() {

}

void SpaceMenu::userInput(SDL_Event *event) {
	if( event->type == SDL_MOUSEBUTTONDOWN ) {
		//If the left mouse button was pressed
		if( event->button.button == SDL_BUTTON_LEFT ) {
			//Get the mouse offsets, we had to invert the xaligment because of the relation between the mouse and the hitbox.
			//also the viritual position had to be calculated for the pointer.
			int x = 2*event->button.x-ScreenManager::screenXpos(event->button.x, true);
			int y = 2*event->button.y-ScreenManager::screenYpos(event->button.y, true);

			for (int i=0; i<buttons.size(); i++) {
				//If the mouse is over the button
				if( ( x > buttons[i].x ) && ( x < buttons[i].x + buttons[i].w ) && ( y > buttons[i].y ) && ( y < buttons[i].y + buttons[i].h ) ) {

					//Set the button sprite
					switch(i) {
					case 0:
						parent->setStatus(STATE_RUNNING);
					}
					cout << "click[" << i << "]" << endl;
				}
			}
		}
	}

}
